package com.freewater.springboot.demo.dataaccess.transaction.listener;

import org.springframework.context.event.EventListener;
import org.springframework.transaction.event.TransactionalEventListener;

public class OrderEventListener {

    // @TransactionalEventListener 默认当前线程的事务提交成功后触发，否则不触发
    @TransactionalEventListener
    public void onOrderCreatedTransactionListener(OrderCreatedEvent event) {
        System.out.println("onOrderCreatedTransactionListener >>> 订单创建成功，订单ID：" + event.getOrderId());
    }

    // @EventListener 只要发布了事件就会触发
    @EventListener
    public void onOrderCreatedNormalListener(OrderCreatedEvent event) {
        System.out.println("onOrderCreatedNormalListener >>> 订单创建成功，订单ID：" + event.getOrderId());
    }
}
